package com.vdg.fps.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.vdg.R;
import com.vdg.fps.data.FaceBookAccount;
import com.vdg.fps.ui.view.TextViewPlus;
import com.vdg.fps.ulti.Utilities;

public class ListFaceBookAccountsAdapter extends ArrayAdapter<FaceBookAccount> {
	private List<FaceBookAccount> mListFaceBookAccounts;

	public ListFaceBookAccountsAdapter(Context context, int textViewResourceId,
			List<FaceBookAccount> objects) {
		super(context, textViewResourceId, objects);
		mListFaceBookAccounts = objects;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		FaceBookAccount account = mListFaceBookAccounts.get(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(getContext()).inflate(
					R.layout.accounts_row, parent, false);
			holder.mTxvName = (TextViewPlus) convertView
					.findViewById(R.id.txv_name);
			holder.mTxvSchedules = (TextViewPlus) convertView
					.findViewById(R.id.txv_schedules);
			holder.mTxvUserProxy = (TextViewPlus) convertView
					.findViewById(R.id.txv_proxy);
			holder.mTxvLasPost = (TextViewPlus) convertView
					.findViewById(R.id.txv_lastpost);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (account != null) {
			String name = account.getUserName();
			String id = account.getID();
			String lastPost = "N/A";
			if (account.getLastPost() != 0) {
				lastPost = Utilities.getTimeDisplay(account.getLastPost());
			}

			String schedules = "0";
			String uerProxy = "NO";
			if (account.getProxy() != null) {
				uerProxy = "YES";
			}
			holder.mTxvUserProxy.setText(uerProxy);
			holder.mTxvLasPost.setText(lastPost);
			holder.mTxvSchedules.setText(schedules);
			holder.mTxvLasPost.setText(lastPost);
			holder.mTxvName.setText(name);
		}
		return convertView;
	}

	public static class ViewHolder {
		private TextViewPlus mTxvName;
		private TextViewPlus mTxvSchedules;
		private TextViewPlus mTxvUserProxy;
		private TextViewPlus mTxvLasPost;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListFaceBookAccounts.size();
	}
}
